﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMP.Windows.Utility
{
    using System.Security.Cryptography;
    public static class Text
    {
        /// <summary>
        /// Get string between
        /// </summary>
        /// <param name="str">String need to get</param>
        /// <param name="start">String start</param>
        /// <param name="end">String end</param>
        /// <returns>String</returns>
        public static string GetBetween(string str, string start, string end)
        {
            try
            {
                var s = str.IndexOf(start);
                var e = str.IndexOf(end);

                return str.Substring(s, e - s);
            }
            catch { return ""; }
        }

        /// <summary>
        /// Get string between
        /// </summary>
        /// <param name="str">String need to get</param>
        /// <param name="start">Char start</param>
        /// <param name="end">Char end</param>
        /// <returns>String</returns>
        public static string GetBetween(string str, char start, char end)
        {
            try
            {
                var s = str.IndexOf(start);
                var e = str.IndexOf(end);

                return str.Substring(s, e - s);
            }
            catch { return ""; }
        }

        public static string ToAllUpper(string str)
        {
            try
            {
                str = str.Trim();
                string result = "";
                for (int i = 0; i < str.Length; i++)
                {
                    string s = str[i].ToString();
                    result += s.ToUpper();
                }
                return result;
            }
            catch(Exception) {return null;}

        }

        public static string EncodeMD5(string inputString)
        {
            MD5 md5 = MD5.Create();
            byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(inputString));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
                sb.Append(data[i].ToString("x2"));

            return sb.ToString();
        }



    }
}
